package cn.edu.huanu.dao.impl;

import cn.edu.huanu.dao.CategoryDao;
import cn.edu.huanu.exception.DaoException;
import cn.edu.huanu.pojo.Category;
import cn.edu.huanu.utils.ConnectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author hb
 * @date 2025-11-07 09:22:52
 */
public   class CategoryDaoImpl implements CategoryDao {
    /**
     *
     * @param parentId
     * @return
     * @throws DaoException
     * @author 张三丰 202412341234
     */
    @Override
    public List<Category> queryCategoryByParentId(Integer parentId) throws DaoException {
      final   String sql ="select id,name from t_category where parent_id <=> ?";
      return ConnectionUtils.query(sql,rs -> {
            List<Category> lists=new ArrayList<>();
            while(rs.next()){
                Category c=new Category();
                c.setId(rs.getInt("id"));
                c.setName(rs.getString("name"));
                lists.add(c);
            }
            return lists;
        },parentId);
    }
}
